<?php

namespace App\Trip\Crypt;

class Aes
{
    private string $iv  = "";//iv的长度要根据加密方式和模式来定,aes-128-cbc偏移量的是16位
    private string $key = '';

    function __construct()
    {
        // time-sign 用 appid + 时间 验证
        // appid  用 app_key + 指定字符串验证
        $this->key = config('trip.aes.key');
        $this->iv  = config('trip.aes.iv');
    }


    public function encrypt($input): string
    {
        return base64_encode(openssl_encrypt($input, 'AES-128-CBC', $this->key, true, $this->iv));
    }

    public function decrypt($input): bool|string
    {
        return openssl_decrypt(base64_decode($input), 'AES-128-CBC', $this->key, true, $this->iv);
    }

}